const MessageService = require("../sercice/MessageSevire")


const MessageControl = {
    get_message: async (req, res) => {
        try {
            const result = await MessageService.get_message(req.params.skp)
            console.log(result)
            res.send({
                msg: '获取成功',
                data: result.data,
                count: result.count,
                code: 200
            })
        } catch (error) {
            res.status(411).send({
                msg: "获取失败",
                data: "",
                code: 411
            })
        }

    },
    deleteone: async (req, res) => {
        try {
            const result = await MessageService.delete_message(req.params.id)
            console.log(result)
            if (result.deletedCount === 1) {
                res.status(200).send({
                    msg: '删除成功',
                    code: 200
                })
            } else {
                res.status(411).send({
                    msg: "删除失败",
                    code: 411
                })
            }

        } catch (error) {
            res.status(411).send({
                msg: "删除失败",
                code: 411
            })
        }
    }
}

module.exports = MessageControl